package laps.dataaccess.mysql;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import laps.dataaccess.AdministratorDAO;
import laps.model.Administrator;

public class AdministratorDAOImpl implements AdministratorDAO {

	private Connection connection;

	public AdministratorDAOImpl(Connection connection) {
		super();
		this.connection = connection;
	}

	@Override
	public Administrator getAdmin() {
		return new Administrator();
	}

	@Override
	public boolean authenticate(Administrator admin) {
		boolean result = false;
		String username = admin.getUsername();
		String password = admin.getPassword();
		
		String sqlStatement = "select * from laps_db.administrator where " +
							  "username='" + username + "' and " +
							  "password='" + password + "';";
		
		Statement statement = null;
		ResultSet resultSet = null;
		
		try {
			statement = connection.createStatement();
			resultSet = statement.executeQuery(sqlStatement);
			if(resultSet.next()) result=true;
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return result;
	}
	
}
